
#from datetime import datetime
import datetime

#Python Module Imports
import sqlalchemy.exc


import json
import cogentviewer.models as models
import cogentviewer.tests.base as base

class TestNode(base.ModelTestCase):

    def _serialobj(self):
        """Helper Method to provde an object to serialise"""
        theItem = models.Node(id=1,
                              locationId = 2,
                              nodeTypeId = 3)
        return theItem

    def _dictobj(self):
        """Helper method to provide a dictionay representaiton of the object
        generated by _serialobj()"""

        theDict = {"__table__" : "Node",
                   "id" : 1,
                   "locationId" : 2,
                   "nodeTypeId" : 3,
                   }
        return theDict

    def testEq(self):
        """Test for Equality"""
        item1 = models.Node(id=1,
                            locationId = 2,
                            nodeTypeId = 3)

        item2 = models.Node(id=1,
                            locationId = 2,
                            nodeTypeId = 3)


        #In the case of Node,  its only Id that needs
        #To be equal
        self.assertEqual(item1,item2)
        self.assertReallyEqual(item1,item2)

        item2.locationId = 10
        self.assertEqual(item1,item2)
        self.assertReallyEqual(item1,item2)

        item2.locationId = 2
        item2.nodeTypeId = 10
        self.assertEqual(item1,item2)
        self.assertReallyEqual(item1,item2)


    def testNEQ(self):

        item1 = models.Node(id=1,
                            locationId = 2,
                            nodeTypeId = 3)

        item2 = models.Node(id=1,
                            locationId = 2,
                            nodeTypeId = 3)


        self.assertEqual(item1,item2)
        
        item2.id = 2
        self.assertNotEqual(item1,item2)
        self.assertReallyNotEqual(item1,item2)


    def testCmp(self):
        """Test Compaison function

        (actually __lt__ for Py3K Comat)"""


        item1 = models.Node(id=1,
                            locationId = 2,
                            nodeTypeId = 3)

        item2 = models.Node(id=1,
                            locationId = 2,
                            nodeTypeId = 3)
        
        self.assertEqual(item1,item2)
        
        #Order on HouseId
        item2.id = 0
        self.assertGreater(item1,item2)

        item2.id = 2

        self.assertLess(item1,item2)

